package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthInterfaceModel;
import com.snake.springboot.authority.api.request.AuthInterfaceQuery;
import com.snake.springboot.authority.api.service.AuthInterfaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.snake.common.result.ReturnList;
import org.snake.common.validate.Create;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 类 {@code ProjTaskController}  <br> .
 * <p>权限管理-接口控制器
 * 创建时间：2024/4/17 10:11
 *
 * @author Yzhui
 * @see
 */

@Api(tags = "权限管理-接口控制器")
@RestController
@RequestMapping("/auth/interface")
public class AuthInterfaceController {

    private AuthInterfaceService authInterfaceService;

    @Autowired
    public AuthInterfaceController(AuthInterfaceService authInterfaceService) {
        this.authInterfaceService = authInterfaceService;
    }

    @ApiOperation("新增接口")
    @PostMapping("/add")
    public ResponseResult<AuthInterfaceModel> addAuthInterface(
            @ApiParam(name = "接口入参", value = "传入json格式", required = true)
            @RequestBody @Validated({Create.class}) AuthInterfaceModel model) throws Exception {
        AuthInterfaceModel result = authInterfaceService.addInterface(model);
        return ResponseResultFactory.ucc("添加成功！", result);
    }

    @ApiOperation("修改接口")
    @PostMapping("/modify")
    public ResponseResult<AuthInterfaceModel> modifyAuthInterface(
            @ApiParam(name = "接口模型入参", value = "传入json格式", required = true)
            @RequestBody AuthInterfaceModel model) throws Exception {
        authInterfaceService.modifyInterface(model);
        return ResponseResultFactory.ucc("修改成功！");
    }

    @ApiOperation("删除接口")
    @GetMapping("/remove/{interfaceid}")
    public ResponseResult<Object> removeAcceptPerson(
            @ApiParam(name = "记录ID", value = "传入String类型", required = true)
            @PathVariable("interfaceid") String interfaceId) {
        authInterfaceService.removeInterface(interfaceId);
        return ResponseResultFactory.ucc("移除成功！");
    }

    @ApiOperation("查询权限接口列表")
    @PostMapping("/list")
    public ResponseResult<ReturnList<AuthInterfaceModel>> queryAuthInterfaceList(
            @ApiParam(name = "查询条件", value = "传入json类型", required = true)
            @RequestBody AuthInterfaceQuery params) throws Exception {
        ReturnList<AuthInterfaceModel> result = authInterfaceService.queryInterfaceList(params);
        return ResponseResultFactory.ucc("查询成功！", result);
    }


}
